﻿using System;
using System.Collections.Generic;
////using System.Linq;
using System.Text;
using DBConnectionLib;

namespace DBSourceToolsLib.SysObjects
{
    class SysObjectsFactory
    {
        //public SysObject getSysObject(string name, string dbType, string strBaseDirectory
        //    , Database oDatabase)
        //{
        //    //switch (dbType.Trim())
        //    //{
        //    //    case "U": return new SOTable(name, strBaseDirectory,  oDatabase);
        //    //    case "V": return new SOView(name, strBaseDirectory, oDatabase);
        //    //    case "FN": return new SOFunction(name, strBaseDirectory, oDatabase);
        //    //    case "P": return new SOProc(name, strBaseDirectory, oDatabase);
        //    //}
        //    //return null;

        //}

        internal SysObject getSysObject(string strFileName, SysObjectType sysObjectType, Database oDatabase)
        {
            // load from disk
            switch (sysObjectType)
            {
                case SysObjectType.Table:
                    return new SOTable(strFileName, oDatabase);
                case SysObjectType.Proc:
                    return new SOProc(strFileName, oDatabase);
                case SysObjectType.View:
                    return new SOView(strFileName, oDatabase);
                case SysObjectType.Function:
                    return new SOFunction(strFileName, oDatabase);
                case SysObjectType.Querie:
                    return new SOQuery(strFileName, oDatabase);
                case SysObjectType.DataType:
                    return new SODataType(strFileName, oDatabase);
                case SysObjectType.Schema:
                    return new SOSchema(strFileName, oDatabase);
                case SysObjectType.XmlSchema:
                    return new SOXmlSchema(strFileName, oDatabase);
                case SysObjectType.User:
                    return new SOUser(strFileName, oDatabase);
                case SysObjectType.Role:
                    return new SORole(strFileName, oDatabase);
                case SysObjectType.TableType:
                    return new SOTableType(strFileName, oDatabase);
                case SysObjectType.Trigger:
                    return new SOTrigger(strFileName, oDatabase);
                case SysObjectType.Patche:
                    return new SOPatch(strFileName, oDatabase);
                case SysObjectType.Synonym:
                    return new SOSynonym(strFileName, oDatabase);
            }
            return null;
        }

        internal SysObject NewSysObject(string strNewName, SysObject oldSysObject, Database oDatabase)
        {
            switch (oldSysObject.Type)
            {
                case SysObjectType.Function:
                    return new SOFunction(strNewName, oldSysObject.BaseDirectory, oDatabase, oldSysObject.Urn);
                    break;
                case SysObjectType.Proc:
                    return new SOProc(strNewName, oldSysObject.BaseDirectory, oDatabase, oldSysObject.Urn);
                    break;
                case SysObjectType.Querie:
                    return new SOQuery(strNewName, oldSysObject.BaseDirectory, oDatabase);
                    break;
                case SysObjectType.Table:
                    return new SOTable(strNewName, oldSysObject.BaseDirectory, oDatabase, oldSysObject.Urn);
                    break;
                case SysObjectType.View:
                    return new SOView(strNewName, oldSysObject.BaseDirectory, oDatabase, oldSysObject.Urn);
                    break;
            }
            return null;
        }


        //internal SysObject CloneSysObject(SysObject oldSysObject, DatabaseEx targetDatabase)
        //{
        //    switch (oldSysObject.Type)
        //    {
        //        case SysObjectType.Function:
        //            return new SOFunction(oldSysObject, targetDatabase);
        //            break;
        //        case SysObjectType.Proc:
        //            return new SOProc(oldSysObject, targetDatabase);
        //            break;
        //        case SysObjectType.Querie:
        //            return new SOQuery(oldSysObject, targetDatabase);
        //            break;
        //        case SysObjectType.Table:
        //            return new SOTable((SOTable)oldSysObject, targetDatabase);
        //            break;
        //        case SysObjectType.View:
        //            return new SOView(oldSysObject, targetDatabase);
        //            break;
        //        case SysObjectType.DataType:
        //            return new SODataType(oldSysObject, targetDatabase);
        //            break;
        //        case SysObjectType.Schema:
        //            return new SOSchema(oldSysObject, targetDatabase);
        //            break;
        //        case SysObjectType.XmlSchema:
        //            return new SOXmlSchema(oldSysObject, targetDatabase);
        //            break;
        //        case SysObjectType.User:
        //            return new SOUser(oldSysObject, targetDatabase);
        //    }
        //    return null;
        //}
    }
}
